package com.t17;

import java.util.*;

import static net.mindview.util.Print.print;

/**
 * Created by xuyiwei on 2018/8/25.
 */
public class Utilities {
    static List<String> list = Arrays.asList(
            "one Two three Four five six one".split(" "));

    public static void main(String[] args) {
        print(list);
        print("'list' disjoint (Four)?: " +
                //当两个集合没有任何相同元素的时候 返回true
                Collections.disjoint(list,
                        //得到单一Four的list集合
                        Collections.singletonList("Four")));
        //按顺序得到list里面的最大值
        print("max: " + Collections.max(list));
        //按顺序得到list里面的最小值
        print("min: " + Collections.min(list));
        //按String.CASE_INSENSITIVE_ORDER排序得到最大值
        print("max w/ comparator: " + Collections.max(list,
                String.CASE_INSENSITIVE_ORDER));
        //按String.CASE_INSENSITIVE_ORDER排序得到最小值
        print("min w/ comparator: " + Collections.min(list,
                String.CASE_INSENSITIVE_ORDER));
        //数组转换成list
        List<String> sublist =
                Arrays.asList("Four five six".split(" "));
        //返回target在source中第一次出现的位置 或者找不到的时候返回-1
        print("indexOfSubList: " +
                Collections.indexOfSubList(list, sublist));
        //返回target在source中最后一次出现的位置 或者找不到的时候返回-1
        print("lastIndexOfSubList: " +
                Collections.lastIndexOfSubList(list, sublist));
        //拿Yo代替最后一次one
        Collections.replaceAll(list, "one", "Yo");
        print("replaceAll: " + list);
        //反转list
        Collections.reverse(list);
        print("reverse: " + list);
        //将list的所有的元素往后移动3位 把末尾的移上来
        Collections.rotate(list, 3);
        print("rotate: " + list);
        List<String> source =
                Arrays.asList("in the matrix".split(" "));
        //拷贝到source上  这个拷贝是  如果source有的 则不拷贝 如果source里面没有的 则拷贝
        Collections.copy(list, source);
        print("copy: " + list);
        //交换list里面0和list.size()-1的位置
        Collections.swap(list, 0, list.size() - 1);
        print("swap: " + list);
        //随机打乱list的顺序
        Collections.shuffle(list, new Random(47));
        print("shuffled: " + list);
        //list里面填充满pop
        Collections.fill(list, "pop");
        print("fill: " + list);
        //返回list里面等于x的元素个数
        print("frequency of 'pop': " +
                Collections.frequency(list, "pop"));
        //返回大小为n的list<T> 此list不可改变 所有的引用都指向x
        List<String> dups = Collections.nCopies(3, "snap");
        print("dups: " + dups);
        //这样会报错
        //dups.set(1,"ada");
        //两个list没有任何相同的元素返回true
        print("'list' disjoint 'dups'?: " +
                Collections.disjoint(list, dups));
        Enumeration<String> e = Collections.enumeration(dups);
        Vector<String> v = new Vector<String>();
        while (e.hasMoreElements()) {
            v.addElement(e.nextElement());
        }
        ArrayList<String> arrayList =
                Collections.list(v.elements());
        print("arrayList: " + arrayList);
        /**
         * [one, Two, three, Four, five, six, one]
         'list' disjoint (Four)?: false
         max: three
         min: Four
         max w/ comparator: Two
         min w/ comparator: five
         indexOfSubList: 3
         lastIndexOfSubList: 3
         replaceAll: [Yo, Two, three, Four, five, six, Yo]
         reverse: [Yo, six, five, Four, three, Two, Yo]
         rotate: [three, Two, Yo, Yo, six, five, Four]
         copy: [in, the, matrix, Yo, six, five, Four]
         swap: [Four, the, matrix, Yo, six, five, in]
         shuffled: [six, matrix, the, Four, Yo, five, in]
         fill: [pop, pop, pop, pop, pop, pop, pop]
         frequency of 'pop': 7
         dups: [snap, snap, snap]
         'list' disjoint 'dups'?: true
         arrayList: [snap, snap, snap]
         */
    }
}
